<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>地址解析</title>
<style type="text/css">
*{
    margin:0px;
    padding:0px;
}
body, button, input, select, textarea {
    font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
p{
    width:603px;
    padding-top:3px;
    overflow:hidden;
}
#container {
   min-width:603px;
   min-height:767px;
}
input#address{
    width:300px;
}
</style>
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.js"></script>
<script>
var geocoder,map, markers,citylocation = null;
var init = function() {
    var map = new qq.maps.Map(document.getElementById("container"),{
        center: new qq.maps.LatLng(39.916527,116.397128),
        zoom: 13
    });
    var info = new qq.maps.InfoWindow({map: map});
    geocoder = new qq.maps.Geocoder({
        complete : function(result){
            console.log(result);
            map.setCenter(result.detail.location);
        }
    });
    markers = new qq.maps.Geocoder({
        complete : function(result){
            console.log(result);
            parent.getFocus(result);
            map.setCenter(result.detail.location);
        }
    });
    //获取城市列表接口设置中心点
    citylocation = new qq.maps.CityService({
        complete : function(result){
            map.setCenter(result.detail.latLng);
        }
    });
    //调用searchLocalCity();方法    根据用户IP查询城市信息。
    citylocation.searchLocalCity();
    //绑定单击事件添加参数
    qq.maps.event.addListener(map, 'click', function(event) {
        var latLng = new qq.maps.LatLng(event.latLng.getLat(), event.latLng.getLng());
        markers.getAddress(latLng);
        var marker=new qq.maps.Marker({
                position:event.latLng, 
                map:map
          });    
        qq.maps.event.addListener(map, 'click', function(event) {
            marker.setMap(null);      
    });      
    });
  
}

function codeAddress() {
    var address = $('#userAddress',window.parent.document).val();
    //通过getLocation();方法获取位置信息值
    geocoder.getLocation(address);
}
</script>
</head>
<body onload="init()">
<!--<div>-->
    <!--<input id="address" type="textbox" value="长沙,岳麓区">-->
    <!--<button onclick="codeAddress()">搜索</button>-->
<!--</div>-->
<div id="container"></div>
<p>给地图绑定了点击事件，当点击地图时，会弹出点击点的坐标。</p>
</body>
</html>
